package com.allen.apollo.controller;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
  * @Description:描述
  * @Version v1.0.0
  * @author Administrator
  * @date 2022/5/22 19:41
  */
@RestController
@Slf4j
public class IndexController {

    @GetMapping(value = "/getConfig")
    public String index(@Param("namespace") String namespace) {
        Config config = ConfigService.getConfig(namespace);
        String property = config.getProperty("author", "zp");
        log.warn("当前配置为：{}",property);
        return property;
    }


    @PostMapping(value = "/getConfigByKey")
    public String index(@Param("namespace") String namespace,@Param("key") String key) {
        Config config = ConfigService.getConfig(namespace);
        String property = config.getProperty(key, "zp");
        log.warn("当前配置为：{}",property);
        return property;
    }
}
